package zhh.tangbao.wechat.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import zhh.tangbao.system.entity.PagerEntity;
import zhh.tangbao.wechat.dto.commodity.CommodityQueryDto;
import zhh.tangbao.wechat.entity.WeChatUser;
import zhh.tangbao.wechat.vo.WeChatUserCacheVo;
import zhh.tangbao.wechat.vo.WeChatUserListOptionsVo;
import zhh.tangbao.wechat.vo.commodity.CommodityPageInMachineVo;
import zhh.tangbao.wechat.vo.simple.UserIdAndPhoneVo;

import java.util.Collection;
import java.util.List;

/**
 * 2023/2/27
 *
 * @author 粥灰灰
 * @version 1.0
 * 描述
 */

@Repository
@Mapper
public interface WeChatUserDao extends BaseMapper<WeChatUser> {

    /**
     * 通过token查找已经在微信小程序平台登录过的用户的信息
     * 如果没找到则代表用户不存在或者token过期
     * 需要让用户进行一次授权登录
     *
     * @param token
     * @return
     */
    WeChatUserCacheVo getWeChatUserCacheVo(String token);

    @Select("SELECT open_id FROM wechat_user WHERE id = #{id}")
    String getOpenIdByUserId(String id);

    @Select("SELECT id stringKey, phone_number label, phone_number phoneNumber FROM `wechat_user` WHERE phone_number LIKE '%${phoneNumber}%'")
    List<WeChatUserListOptionsVo> userListOptionsByPhoneNumber(@Param("phoneNumber") String phoneNumber);

    List<UserIdAndPhoneVo> listUserIdAndPhoneVoByIds(@Param("ids") Collection<String> ids);

    List<CommodityPageInMachineVo> listCommodityPageInMachineVos(@Param("pager") PagerEntity<CommodityPageInMachineVo> pager,@Param("dto") CommodityQueryDto dto);

    long commodityPageInMachineCount(@Param("pager") PagerEntity<CommodityPageInMachineVo> pager,@Param("dto") CommodityQueryDto dto);
}
